package com.aode.playlist.network;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.aode.common.bean.request.SearchData;
import com.aode.common.bean.response.Mllist;
import com.aode.common.bean.response.Music;
import com.aode.common.bean.web.Result;
import com.aode.playlist.service.MllistService;
import com.aode.playlist.service.MusicService;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class HttpData {
    private static MutableLiveData<Result<List<Music>>> musicMutableLiveData = new MutableLiveData<>();
    private static MutableLiveData<Result<List<Mllist>>> mllistMutableLiveData = new MutableLiveData<>();

    public static MutableLiveData<Result<List<Mllist>>> getMllist(){
        HttpsUtils.getInstance().create(MllistService.class)
                .getMLList()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<Result<List<Mllist>>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull Result<List<Mllist>> listResult) {
                        mllistMutableLiveData.postValue(listResult);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
        return mllistMutableLiveData;
    }


    public static MutableLiveData<Result<List<Music>>> getMusic(SearchData searchData){
        HttpsUtils.getInstance().create(MusicService.class)
                .getMusic(searchData.getSearch())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<Result<List<Music>>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull Result<List<Music>> listResult) {
                        musicMutableLiveData.postValue(listResult);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
        return musicMutableLiveData;
    }
}
